import {
  request
} from '../../../utils/requestUtils';
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    form:{
      type:'',
      pic:'',
      remark:'',
      typeName:'',
      orderId:''
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showhandler(data) {
      console.log('data', data)
      this.setData({
        show: true,
        'form.type':data.type,
        'form.orderId':data.id,
        'form.typeName': data.type == 1 ? '取货' :'送达',
        'form.pic':'',
        'form.remark':''
      })
      this.selectComponent('#listUploader').initListHandler([])

    },
    // 关闭弹窗
    onClose() {
      this.setData({
        show: false
      })
    },
    // 输入框值修改
    onChange(event) {
      switch (event.currentTarget.dataset['input']) {
        case 'remark':
          this.setData({
            "form.remark": event.detail,
          })
          break;
      }
    }, 
    // 保存操作
    async save() {
      let picList = this.selectComponent('#listUploader').data.fileList
      if (!picList || picList.length == 0) {
        wx.showToast({
          title: '图片不能为空',
          icon: 'none'
        })
        return
      }
      console.log('picList', picList)
      const result = await request({
        url: '/bus/rider/operate/returnOrder',
        method: "POST",
        data: { ...this.data.form,...{
          pic:picList.map(v=>v.url).join(',')
        } }
      });
      if (result.data.code == 200) {
        this.setData({
          show: false
        })
        this.triggerEvent('saveResult')
      }
    }
  }
})